﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business.Entities;
using Negocio;

namespace UI.Desktop
{
    public partial class Alumnos : Form
    {
        public Alumnos()
        {
            InitializeComponent();
           this.dgvAlumnos.AutoGenerateColumns = false;
           this.generarColumnas();
            
        }

        private void btnActualizar_Click(object sender, EventArgs e)
        {
            this.Listar();
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void tsbNuevo_Click(object sender, EventArgs e)
        {
            AlumnoDesktop ad = new AlumnoDesktop(ApplicationForm.modoForm.Alta);
            ad.ShowDialog();
            this.Listar();
            
        }

       

        private void tsbBorrar_Click(object sender, EventArgs e)
        {
            if (this.dgvAlumnos.SelectedRows.Count != 0)
            {
                int ID = ((Business.Entities.Persona)this.dgvAlumnos.SelectedRows[0].DataBoundItem).ID;

                AlumnoDesktop ad = new AlumnoDesktop(ID,ApplicationForm.modoForm.Baja);
                ad.ShowDialog();

            }
        }

        private void generarColumnas()
        {
            DataGridViewTextBoxColumn colId = new DataGridViewTextBoxColumn();
            colId.Name = "id";
            colId.HeaderText = "Id";
            colId.DataPropertyName = "id";
            colId.DisplayIndex = 0;
            this.dgvAlumnos.Columns.Add(colId);

            DataGridViewTextBoxColumn colNombre = new DataGridViewTextBoxColumn();
            colNombre.Name = "nombre";
            colNombre.HeaderText = "Nombre";
            colNombre.DataPropertyName = "nombre";
            colNombre.DisplayIndex = 1;
            this.dgvAlumnos.Columns.Add(colNombre);

            DataGridViewTextBoxColumn colApellido = new DataGridViewTextBoxColumn();
            colApellido.Name = "apellido";
            colApellido.HeaderText = "Apellido";
            colApellido.DataPropertyName = "apellido";
            colApellido.DisplayIndex = 2;
            this.dgvAlumnos.Columns.Add(colApellido);

            DataGridViewTextBoxColumn colDireccion = new DataGridViewTextBoxColumn();
            colDireccion.Name = "direccion";
            colDireccion.HeaderText = "Direccion";
            colDireccion.DataPropertyName = "direccion";
            colDireccion.DisplayIndex = 3;
            this.dgvAlumnos.Columns.Add(colDireccion);

            DataGridViewTextBoxColumn colEmail = new DataGridViewTextBoxColumn();
            colEmail.Name = "email";
            colEmail.HeaderText = "Email";
            colEmail.DataPropertyName = "email";
            colEmail.DisplayIndex = 4;
            this.dgvAlumnos.Columns.Add(colEmail);

            DataGridViewTextBoxColumn colTelefono = new DataGridViewTextBoxColumn();
            colTelefono.Name = "telefono";
            colTelefono.HeaderText = "Telefono";
            colTelefono.DataPropertyName = "telefono";
            colTelefono.DisplayIndex = 5;
            this.dgvAlumnos.Columns.Add(colTelefono);

            DataGridViewTextBoxColumn colFecha_nac = new DataGridViewTextBoxColumn();
            colFecha_nac.Name = "fecha_nac";
            colFecha_nac.HeaderText = "Fecha de Nacimiento";
            colFecha_nac.DataPropertyName = "Fechanacimiento";
            colFecha_nac.DisplayIndex = 6;
            this.dgvAlumnos.Columns.Add(colFecha_nac);

            DataGridViewTextBoxColumn colLegajo = new DataGridViewTextBoxColumn();
            colLegajo.Name = "legajo";
            colLegajo.HeaderText = "Legajo";
            colLegajo.DataPropertyName = "legajo";
            colLegajo.DisplayIndex = 7;
            this.dgvAlumnos.Columns.Add(colLegajo);

            DataGridViewTextBoxColumn colId_plan = new DataGridViewTextBoxColumn();
            colId_plan.Name = "id_plan";
            colId_plan.HeaderText = "Plan";
            colId_plan.DataPropertyName = "Idplan";
            colId_plan.DisplayIndex = 8;
            this.dgvAlumnos.Columns.Add(colId_plan);
        }

        private void Alumnos_Load(object sender, EventArgs e)
        {
            this.Listar();
        }

        public void Listar()
        {
            PersonaLogic pl = new PersonaLogic();
            this.dgvAlumnos.DataSource = pl.GetAllAlumnos();
        }

        private void tsbEditar_Click(object sender, EventArgs e)
        {
            if (this.dgvAlumnos.SelectedRows.Count != 0)
            {
                int ID = ((Business.Entities.Persona)this.dgvAlumnos.SelectedRows[0].DataBoundItem).ID;

                AlumnoDesktop ad = new AlumnoDesktop(ID,ApplicationForm.modoForm.Modificacion);
                ad.ShowDialog();

            }
        }


    }
}
